package com.ssm.controller;

import com.ssm.entity.PmsProduct;
import com.ssm.service.PmsProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品信息(PmsProduct)表控制层
 *
 * @author makejava
 * @since 2020-08-31 11:43:39
 */
@RestController
@RequestMapping("/pmsProduct")
public class PmsProductController {
    /**
     * 服务对象
     */
    @Resource
    private PmsProductService pmsProductService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public PmsProduct selectOne(Long id) {
        return this.pmsProductService.queryById(id);
    }


    @PostMapping("/inittable")
    public HashMap inittable(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                      @RequestParam(value = "rows", defaultValue = "30")Integer rows){
        List<PmsProduct> pmsProducts = pmsProductService.queryAllByLimit(page*rows-rows, rows);
        int c=pmsProductService.queryTotal();
        HashMap res = new HashMap<>();
        res.put("total", c);
        res.put("rows", pmsProducts);
        return res;
    }


}
